/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shxzz.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shxzz.shortlink.admin.common.convention.result.Result;
import com.shxzz.shortlink.admin.remote.LinkRemoteService;
import com.shxzz.shortlink.admin.remote.dto.req.GroupLinkAccessRecordReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.GroupLinkStatusReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.LinkAccessRecordReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.LinkStatusReqDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.GroupLinkAccessRecordRespDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.GroupLinkStatusRespDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.LinkAccessRecordRespDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.LinkStatusRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shxzz
 * @create 2023-12-29-13:53
 * @description 短链接监控控制层
 */
@RestController
@RequiredArgsConstructor
public class LinkStatsController {

    /**
     * 后续重构为 SpringCloud Feign 调用
     */
    LinkRemoteService linkRemoteService = new LinkRemoteService() {
    };

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats")
    public Result<LinkStatusRespDTO> shortLinkStats(LinkStatusReqDTO requestParam) {
        return linkRemoteService.shortLinkStats(requestParam);
    }

    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/group")
    public Result<GroupLinkStatusRespDTO> groupShortLinkStats(GroupLinkStatusReqDTO requestParam) {
        return linkRemoteService.groupShortLinkStats(requestParam);
    }

    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record")
    public Result<IPage<LinkAccessRecordRespDTO>> shortLinkStatsAccessRecord(LinkAccessRecordReqDTO requestParam) {
        return linkRemoteService.shortLinkStatsAccessRecord(requestParam);
    }

    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record/group")
    public Result<IPage<GroupLinkAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(GroupLinkAccessRecordReqDTO requestParam) {
        return linkRemoteService.groupShortLinkStatsAccessRecord(requestParam);
    }
}
